﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;

using Data;

namespace RCFlightTimer
{
	public class AddAircraftFragment : DialogFragment
	{
		public override Dialog OnCreateDialog (Bundle savedInstanceState)
		{
			base.OnCreateDialog (savedInstanceState);

			LayoutInflater inflater = this.Activity.LayoutInflater;
			View view = inflater.Inflate (Resource.Layout.NewObject, null);

			var builder = new AlertDialog.Builder (Activity)
				.SetView (view)
				.SetPositiveButton("Ok", (sender, args) =>
					{
						//Create the new aircraft
						Aircraft ac = new Aircraft();
						ac.type = AircraftType.Airplane;
						ac.name = view.FindViewById<TextView>(Resource.Id.newName).Text;

						//Add it to the database
						Database db = Database.Instance;
						db.AddOrUpdateAircraft(ac);

						var myActivity =(AircraftActivity)this.Activity;
						myActivity.setSelected(ac);
						myActivity.updateFields();
					})

				.SetNegativeButton("Cancel", (sender, args) =>
					{
						// Do something when this button is clicked.
					})
				.SetTitle("Enter a name...");
			return builder.Create();
		}
	}
}

